package scripts;
import bot.ScriptMethods;

public class GnomeAgility extends ScriptMethods implements Runnable {

	private int stage;

	public void start() {
		System.gc();
		getAccountSettings();

		scriptRunning = true;
		scriptThread = new Thread(this);
		scriptThread.start();
	}

	public void stop() {
		System.gc();
		scriptThread = null;
		scriptRunning = false;
		debug("Stopped script.");
	}

	public void run() {
		while (scriptRunning) {
			try {
				handleEvents();

				if ((ourPlayerX() == 692) && (ourPlayerY() == 499))
					stage = 1;
				if ((ourPlayerX() == 692) && (ourPlayerY() == 1448))
					stage = 2;
				if ((ourPlayerX() == 693) && (ourPlayerY() == 2394))
					stage = 3;
				if ((ourPlayerX() == 685) && (ourPlayerY() == 2396))
					stage = 4;
				if ((ourPlayerX() == 683) && (ourPlayerY() == 506))
					stage = 5;
				if ((stage == 5) && (ourPlayerY() == 501))
					stage = 6;
				if ((stage == 6) && (ourPlayerX() == 683) && (ourPlayerY() == 494))
					stage = 0;

				if (!isSleeping()) {
					switch (stage) {
						case 1:
							atObject(692, 503);
							wait(random(800, 1200));
						break;

						case 2:
							atObject(693, 1452);
							wait(random(800, 1200));
						break;

						case 3:
							atObject(689, 2395);
							wait(random(800, 1200));
						break;

						case 4:
							atObject(683, 2396);
							wait(random(800, 1200));
						break;

						case 5:
							atObject(683, 502);
							wait(random(800, 1200));
						break;

						case 6:
							atObject(683, 497);
							wait(random(800, 1200));
						break;

						case 0:
							atObject(692, 495);
							wait(random(800, 1200));
						break;
					}
				}
				wait(100);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void handleEvents() throws Exception {
		if (welcomeBoxOpen())
			setWelcomeBox();
		if (!isLoggedIn())
			doLogin();
		if (getFatigue() > 80 && !isSleeping()) {
			wait(600);
			useItem(1263);
			wait(600);
		}
		if (getFatigueSleeping() < 10 && isSleeping())
			doSleeping();
	}
}